function [zero, one, two, three, four, five, six, seven, eight, nine] = readImages(filename)

zero = []; one = []; two = []; three = []; four = []; 
five = []; six = []; seven = []; eight = []; nine = []; 

A = textread(filename, '', 'endofline', '\n', 'delimiter', ' ');

for i = 0:9
    ind = find(A(:,1) == i);
    
    for j = ind
        images = reshape(transpose(A(j,2:2+16*16-1)),16,16,size(ind,1));
        
        for k = 1:size(images,3)
            images(:,:,k) = transpose(images(:,:,k));   
%             imshow(images(:,:,k));
        end 
        
        % rescale to 0-1 range
        images = ((images+1)/2);
    end
    
    % store image details
    if(i == 0)
        zero = images;
    elseif(i == 1)
        one = images;
    elseif(i == 2)
        two = images;
    elseif(i == 3)
        three = images;
    elseif(i == 4)
        four = images;
    elseif(i == 5)
        five = images;
    elseif(i == 6)
        six = images;
    elseif(i == 7)
        seven = images;
    elseif(i == 8)
        eight = images;
    elseif(i == 9)
        nine = images;        
    end  

end

end